﻿/**
* 游戏类NanamiProject
*/
var nanamiproject = function (title) {
	$(document)[0].title = title;
	//实例化
	var that = {
	//初始化函数	
		init: function(gameWidth, gameHeight){
			// 计算画布距窗口最左像素：left = 窗口宽度/2 - 400（画布宽度的一半）
			var left = $(window).width() / 2 - gameWidth / 2,
				right = $(window).width() / 2 + gameWidth / 2;
			// 应用到所有的元素上
			$('#background1').css({'left':left, 'width':gameWidth, 'height':gameHeight});
			$('#background2').css({'left':left, 'width':gameWidth, 'height':gameHeight});
			$('#characterimage').css({'left':left, 'width':gameWidth, 'height':gameHeight});
			$('#textwindow').css({'left':left, 'width':gameWidth, 'height':gameHeight});
			$('#sprite').css({'left':left, 'width':gameWidth, 'height':gameHeight});
			$('#spritetext').css({'left':left, 'width':gameWidth, 'height':gameHeight});
			$('#top').css({'left':left, 'width':gameWidth, 'height':gameHeight});
			$('#debug').css({'left':right, 'width':200, 'height':600, 'display':'none'});
			// 说明信息
			$('#information').css({"left":$(window).width()/2-149, "top":gameHeight + 20});
			// 实例化
			bg = background();
			ci = characterimage();
            tw = textwindow();
            km = keyboardmouse();
			se = soundeffect();
			sm = spriteManager();
			sys = system();
            //绑定点击到km.click函数上
            $('#top').mousedown(function(event){km.click(event)});
			// 绑定按键到km.press函数上
			$(document).keypress(function (event) {km.press(event)});
			// 屏蔽上下文菜单
			$('#top').bind("contextmenu", function (){return false});
			//执行剧本
            sys.scriptLoop();
		}
	};
	return that;
}